package rev3;

import static org.junit.Assert.*;

import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import java.util.Random;
import java.util.StringTokenizer;

import org.junit.Assert;
import org.junit.Test;

import rev3.MyString;
import rev3.NodeMyString;

public class Rev3TestPuts {

	@Test
	public void test1()
	{
		NodeMyString comp = null;
		try {
            Registry registry = LocateRegistry.getRegistry();
            //NodeMyString.class.getProtectionDomain().getCodeSource().getLocation();
            
            String name = "n5";
            // Get the remote ref
            comp = (NodeMyString) registry.lookup(name);
            System.out.println("found node "+name);
            
            MyString ms1 = new MyString("billy", "clinton", "16");
            comp.put("16::billy", ms1);
            
            name = "n30";
            // Get the remote ref
            comp = (NodeMyString) registry.lookup(name);
            System.out.println("found node "+name);
            
            ms1 = new MyString("frank", "frankenstein", "56");
            comp.put("56::frank", ms1);
            
            // This will cause a namespace wrap-around
            name = "n1";
            // Get the remote ref
            comp = (NodeMyString) registry.lookup(name);
            System.out.println("found node "+name);
            
            ms1 = new MyString("deepak", "patri", "4");
            comp.put("4::depak", ms1);
            
        } catch (Exception e) {
            System.err.println("NodeMyString exception:");
            e.printStackTrace();
        }

		
/*		MyString ms1 = new MyString("mike", "michalak", "40");
		n30.map.put("mike", ms1);
		
		MyString retMyStr = n5.get("40::mike");
		assertTrue("michalak".equalsIgnoreCase(retMyStr.getMyString()) );
		
		// This requires several jumps
		MyString ms2 = new MyString("dr", "zhivago", "93");
		n90.map.put("dr", ms2);
		
		retMyStr = n5.get("93::dr");
		assertTrue("zhivago".equalsIgnoreCase(retMyStr.getMyString()) );
		
		// Test non-existant value
		retMyStr = n1.get("44::not_there");
		assertNull(retMyStr);
		
		// This requires several jumps
		MyString ms3 = new MyString("barack", "obama", "115");
		n112.map.put("barack", ms3);
		
		retMyStr = n1.get("115::barack");
		assertTrue("obama".equalsIgnoreCase(retMyStr.getMyString()) );*/
	}
	

}
